<!DOCTYPE html>
<html class="writer-html5" lang="en" data-content_root="../../">
<head>
  <meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1" />

  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>use_module/2 &mdash; The Logtalk Handbook v3.93.0-b01 documentation</title>
      <link rel="stylesheet" type="text/css" href="../../_static/pygments.css?v=d75fae25" />
      <link rel="stylesheet" type="text/css" href="../../_static/css/theme.css?v=19f00094" />
      <link rel="stylesheet" type="text/css" href="../../_static/css/custom.css?v=396eccfe" />

  
  <!--[if lt IE 9]>
    <script src="../../_static/js/html5shiv.min.js"></script>
  <![endif]-->
  
        <script src="../../_static/jquery.js?v=5d32c60e"></script>
        <script src="../../_static/_sphinx_javascript_frameworks_compat.js?v=2cd50e6c"></script>
        <script src="../../_static/documentation_options.js?v=c8100655"></script>
        <script src="../../_static/doctools.js?v=9a2dae69"></script>
        <script src="../../_static/sphinx_highlight.js?v=dc90522c"></script>
    <script src="../../_static/js/theme.js"></script>
    <!-- begin favicon -->
    <link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png" />
    <link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png" />
    <link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png" />
    <link rel="manifest" href="/site.webmanifest" />
    <link rel="mask-icon" href="/safari-pinned-tab.svg" color="#5bbad5" />
    <meta name="msapplication-TileColor" content="#355b95" />
    <meta name="theme-color" content="#ffffff" />
    <!-- end favicon -->
    
    <link rel="index" title="Index" href="../../genindex.html" />
    <link rel="search" title="Search" href="../../search.html" />
    <link rel="next" title="Built-in predicates" href="../predicates/index.html" />
    <link rel="prev" title="uses/2" href="uses_2.html" />
   
</head>

<body class="wy-body-for-nav"> 
  <div class="wy-grid-for-nav">
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search" >

          
          
          <a href="../../index.html" class="icon icon-home">
            The Logtalk Handbook
              <img src="../../_static/logtalk.gif" class="logo" alt="Logo"/>
          </a>
              <div class="version">
                3.93.0
              </div>
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" aria-label="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>
        </div><div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu">
    
              <p class="caption" role="heading"><span class="caption-text">Contents</span></p>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../../userman/index.html">User Manual</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="../index.html">Reference Manual</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="../grammar.html">Grammar</a></li>
<li class="toctree-l2"><a class="reference internal" href="../control/index.html">Control constructs</a></li>
<li class="toctree-l2 current"><a class="reference internal" href="index.html">Directives</a><ul class="current">
<li class="toctree-l3"><a class="reference internal" href="source_file_directives.html">Source file directives</a></li>
<li class="toctree-l3"><a class="reference internal" href="conditional_compilation_directives.html">Conditional compilation directives</a></li>
<li class="toctree-l3"><a class="reference internal" href="entity_directives.html">Entity directives</a></li>
<li class="toctree-l3 current"><a class="reference internal" href="predicate_directives.html">Predicate directives</a><ul class="current">
<li class="toctree-l4"><a class="reference internal" href="alias_2.html"><code class="docutils literal notranslate"><span class="pre">alias/2</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="coinductive_1.html"><code class="docutils literal notranslate"><span class="pre">coinductive/1</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="discontiguous_1.html"><code class="docutils literal notranslate"><span class="pre">discontiguous/1</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="dynamic_1.html"><code class="docutils literal notranslate"><span class="pre">dynamic/1</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="info_2.html"><code class="docutils literal notranslate"><span class="pre">info/2</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="meta_predicate_1.html"><code class="docutils literal notranslate"><span class="pre">meta_predicate/1</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="meta_non_terminal_1.html"><code class="docutils literal notranslate"><span class="pre">meta_non_terminal/1</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="mode_2.html"><code class="docutils literal notranslate"><span class="pre">mode/2</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="multifile_1.html"><code class="docutils literal notranslate"><span class="pre">multifile/1</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="op_3.html"><code class="docutils literal notranslate"><span class="pre">op/3</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="private_1.html"><code class="docutils literal notranslate"><span class="pre">private/1</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="protected_1.html"><code class="docutils literal notranslate"><span class="pre">protected/1</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="public_1.html"><code class="docutils literal notranslate"><span class="pre">public/1</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="synchronized_1.html"><code class="docutils literal notranslate"><span class="pre">synchronized/1</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="uses_2.html"><code class="docutils literal notranslate"><span class="pre">uses/2</span></code></a></li>
<li class="toctree-l4 current"><a class="current reference internal" href="#"><code class="docutils literal notranslate"><span class="pre">use_module/2</span></code></a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../predicates/index.html">Built-in predicates</a></li>
<li class="toctree-l2"><a class="reference internal" href="../methods/index.html">Built-in methods</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../tutorial/index.html">Tutorial</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../faq/index.html">FAQ</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../devtools/index.html">Developer Tools</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../libraries/index.html">Libraries</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../ports/index.html">Ports</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../contributions/index.html">Contributions</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../glossary.html">Glossary</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../bibliography.html">Bibliography</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../genindex.html">Index</a></li>
</ul>

    <p class="caption"><span class="caption-text">External Contents</span></p>
    <ul>
    <li class="toctree-l1"><a class="reference internal" href="../../../apis/index.html">APIs</a></li>
    <li class="toctree-l1"><a class="reference internal" href="https://logtalk.org">Logtalk website</a></li>
    <li class="toctree-l1"><a class="reference internal" href="https://github.com/LogtalkDotOrg/logtalk3">GitHub repo</a></li>
    </ul>
  
        </div>
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"><nav class="wy-nav-top" aria-label="Mobile navigation menu" >
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../../index.html">The Logtalk Handbook</a>
      </nav>

      <div class="wy-nav-content">
        <div class="rst-content">
          <div role="navigation" aria-label="Page navigation">
  <ul class="wy-breadcrumbs">
      <li><a href="../../index.html" class="icon icon-home" aria-label="Home"></a></li>
          <li class="breadcrumb-item"><a href="../index.html">Reference Manual</a></li>
          <li class="breadcrumb-item"><a href="index.html">Directives</a></li>
          <li class="breadcrumb-item"><a href="predicate_directives.html">Predicate directives</a></li>
      <li class="breadcrumb-item active"><code class="docutils literal notranslate"><span class="pre">use_module/2</span></code></li>
      <li class="wy-breadcrumbs-aside">
              <a href="https://github.com/LogtalkDotOrg/logtalk3/blob/master/docs/handbook/sources/refman/directives/use_module_2.rst" class="fa fa-github"> Edit on GitHub</a>
      </li>
  </ul>
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
             
  <p class="align-right"><strong>directive</strong></p>
<section id="use-module-2">
<span id="directives-use-module-2"></span><span id="index-0"></span><h1><code class="docutils literal notranslate"><span class="pre">use_module/2</span></code><a class="headerlink" href="#use-module-2" title="Link to this heading"></a></h1>
<section id="description">
<h2>Description<a class="headerlink" href="#description" title="Link to this heading"></a></h2>
<div class="highlight-logtalk notranslate"><div class="highlight"><pre><span></span>use_module(<span class="nv">Module</span>, [<span class="nv">Name</span><span class="o">/</span><span class="nv">Arity</span>, ...])
use_module(<span class="nv">Module</span>, [<span class="nv">Name</span><span class="o">/</span><span class="nv">Arity</span> <span class="o">as</span> <span class="nv">Alias</span><span class="o">/</span><span class="nv">Arity</span>, ...])

use_module(<span class="nv">Module</span>, [<span class="nv">Predicate</span> <span class="o">as</span> <span class="nv">Alias</span>, ...])

use_module(<span class="nv">Module</span>, [<span class="nv">Name</span><span class="o">//</span><span class="nv">Arity</span>, ...])
use_module(<span class="nv">Module</span>, [<span class="nv">Name</span><span class="o">//</span><span class="nv">Arity</span> <span class="o">as</span> <span class="nv">Alias</span><span class="o">//</span><span class="nv">Arity</span>, ...])

use_module(<span class="nv">Module</span>, [<span class="k">op</span>(<span class="nv">Precedence</span>,<span class="nv">Associativity</span>,<span class="nv">Operator</span>), ...])
</pre></div>
</div>
<p>This directive declares that all calls (made from predicates defined in
the category or object containing the directive) to the specified
predicates (or non-terminals) are to be interpreted as calls to
explicitly-qualified module predicates (or non-terminals). Thus, this
directive may be used to simplify the writing of predicate definitions by
allowing the programmer to omit the <code class="docutils literal notranslate"><span class="pre">Module:</span></code> prefix when using the
predicates listed in the directive (as long as the predicate calls do
not occur as arguments for non-standard Prolog meta-predicates not
declared on the adapter files). It is also possible to include operator
declarations in the second argument.</p>
<p>This directive is also taken into account when compiling calls to the
<a class="reference internal" href="../../userman/predicates.html#predicates-database"><span class="std std-ref">database</span></a> and
<a class="reference internal" href="../../userman/predicates.html#predicates-reflection"><span class="std std-ref">reflection</span></a> built-in methods by looking
into these methods predicate arguments if bound at compile-time.</p>
<p>It is possible to specify a predicate alias using the notation
<code class="docutils literal notranslate"><span class="pre">Name/Arity</span> <span class="pre">as</span> <span class="pre">Alias/Arity</span></code> or, in alternative, the notation
<code class="docutils literal notranslate"><span class="pre">Name/Arity:Alias/Arity</span></code>. Aliases may be used either for avoiding
conflicts between predicates specified in <code class="docutils literal notranslate"><span class="pre">use_module/2</span></code> and
<a class="reference internal" href="uses_2.html#directives-uses-2"><span class="std std-ref">uses/2</span></a> directives or for giving more meaningful
names considering the calling context of the predicates. For predicates,
it is also possible to define alias shorthands using the notation
<code class="docutils literal notranslate"><span class="pre">Predicate</span> <span class="pre">as</span> <span class="pre">Alias</span></code> or, in alternative, the notation
<code class="docutils literal notranslate"><span class="pre">Predicate::Alias</span></code>, where <code class="docutils literal notranslate"><span class="pre">Predicate</span></code> and <code class="docutils literal notranslate"><span class="pre">Alias</span></code> are callable
terms where some or all arguments may be instantiated.</p>
<p>Note that this directive differs from the directive with the same name
found on some Prolog implementations by requiring the first argument to
be a module name (an atom) instead of a file specification. In Logtalk,
there’s no mixing between <em>loading</em> a resource and (declaring the)
<em>using</em> (of) a resource. As a consequence, this directive doesn’t
automatically load the module. Loading the module file is dependent on
the used <a class="reference internal" href="../../glossary.html#term-backend-Prolog-compiler"><span class="xref std std-term">backend Prolog compiler</span></a> and must be done separately (usually,
using a source file directive such as <code class="docutils literal notranslate"><span class="pre">use_module/1</span></code> or <code class="docutils literal notranslate"><span class="pre">use_module/2</span></code>
in the entity file or preferably in the application <a class="reference internal" href="../../glossary.html#term-loader-file"><span class="xref std std-term">loader file</span></a>
file). Also, note that the name of the module may differ from the name of
the module file.</p>
<div class="admonition warning">
<p class="admonition-title">Warning</p>
<p>The modules <strong>must</strong> be loaded prior to the compilation of entities
that call the module predicates. This is required in general to allow
the compiler to check if the called module predicate is a meta-predicate
and retrieve its meta-predicate template to ensure proper call compilation.</p>
</div>
<p>The module identifier argument can also be a <a class="reference internal" href="../../glossary.html#term-parameter-variable"><span class="xref std std-term">parameter variable</span></a>
when using the directive in a parametric object or a parametric category
defined in a source file (the common case). In this case, <a class="reference internal" href="../../glossary.html#term-dynamic-binding"><span class="xref std std-term">dynamic binding</span></a>
will be used for all listed predicates (and non-terminals). The parameter
variable must be instantiated at runtime when the calls are made.</p>
</section>
<section id="template-and-modes">
<h2>Template and modes<a class="headerlink" href="#template-and-modes" title="Link to this heading"></a></h2>
<div class="highlight-logtalk notranslate"><div class="highlight"><pre><span></span>use_module(<span class="o">+</span>module_identifier, <span class="o">+</span>predicate_indicator_list)
use_module(<span class="o">+</span>module_identifier, <span class="o">+</span>module_predicate_indicator_alias_list)

use_module(<span class="o">+</span>module_identifier, <span class="o">+</span>predicate_template_alias_list)

use_module(<span class="o">+</span>module_identifier, <span class="o">+</span>non_terminal_indicator_list)
use_module(<span class="o">+</span>module_identifier, <span class="o">+</span>module_non_terminal_indicator_alias_list)

use_module(<span class="o">+</span>module_identifier, <span class="o">+</span>operator_list)
</pre></div>
</div>
</section>
<section id="examples">
<h2>Examples<a class="headerlink" href="#examples" title="Link to this heading"></a></h2>
<div class="highlight-logtalk notranslate"><div class="highlight"><pre><span></span><span class="p">:- </span><span class="k">use_module</span>(lists, [append<span class="o">/</span><span class="m">3</span>, member<span class="o">/</span><span class="m">2</span>]).
<span class="p">:- </span><span class="k">use_module</span>(store, [data<span class="o">/</span><span class="m">2</span>]).
<span class="p">:- </span><span class="k">use_module</span>(user,  [foo<span class="o">/</span><span class="m">1</span> <span class="o">as</span> bar<span class="o">/</span><span class="m">1</span>]).

foo <span class="o">:-</span>
    ...,
    <span class="c">% same as findall(X, lists:member(X, L), A)</span>
    <span class="k">findall</span>(<span class="nv">X</span>, member(<span class="nv">X</span>, <span class="nv">L</span>), <span class="nv">A</span>),
    <span class="c">% same as lists:append(A, B, C)</span>
    append(<span class="nv">A</span>, <span class="nv">B</span>, <span class="nv">C</span>),
    <span class="c">% same as assertz(store:data(X, C))</span>
    <span class="k">assertz</span>(data(<span class="nv">X</span>, <span class="nv">C</span>)),
    <span class="c">% same as retractall(user:foo(_))</span>
    <span class="k">retractall</span>(bar(<span class="nv">_</span>)),
    ...
</pre></div>
</div>
<p>Another example, using the extended notation that allows us to define
predicate aliases:</p>
<div class="highlight-logtalk notranslate"><div class="highlight"><pre><span></span><span class="p">:- </span><span class="k">use_module</span>(ugraphs, [transpose_ugraph<span class="o">/</span><span class="m">2</span> <span class="o">as</span> transpose<span class="o">/</span><span class="m">2</span>]).

convert_graph <span class="o">:-</span>
    ...,
    <span class="c">% the same as ugraphs:transpose_ugraph(Graph0, Graph)</span>
    transpose(<span class="nv">Graph0</span>, <span class="nv">Graph</span>),
    ...
</pre></div>
</div>
<p>An example of defining a predicate alias that is also a shorthand:</p>
<div class="highlight-logtalk notranslate"><div class="highlight"><pre><span></span><span class="p">:- </span><span class="k">use_module</span>(pairs, [
    map_list_to_pairs(length, <span class="nv">Lists</span>, <span class="nv">Pairs</span>) <span class="o">as</span> length_pairs(<span class="nv">Lists</span>, <span class="nv">Pairs</span>)
]).
</pre></div>
</div>
<p>An example of using a <a class="reference internal" href="../../glossary.html#term-parameter-variable"><span class="xref std std-term">parameter variable</span></a> in place of the module
identifier to delay to runtime the actual module to use:</p>
<div class="highlight-logtalk notranslate"><div class="highlight"><pre><span></span><span class="p">:- </span><span class="k">object</span>(bar(<span class="nv">_OptionsModule_</span>)).

<span class="p">    :- </span><span class="k">use_module</span>(<span class="nv">_OptionsModule_</span>, [
        set<span class="o">/</span><span class="m">2</span>, get<span class="o">/</span><span class="m">2</span>, reset<span class="o">/</span><span class="m">0</span>
    ]).
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="use_module_1.html#directives-use-module-1"><span class="std std-ref">use_module/1</span></a>,
<a class="reference internal" href="uses_2.html#directives-uses-2"><span class="std std-ref">uses/2</span></a>,
<a class="reference internal" href="uses_1.html#directives-uses-1"><span class="std std-ref">uses/1</span></a>,
<a class="reference internal" href="alias_2.html#directives-alias-2"><span class="std std-ref">alias/2</span></a></p>
</div>
</section>
</section>


           </div>
          </div>
          <footer><div class="rst-footer-buttons" role="navigation" aria-label="Footer">
        <a href="uses_2.html" class="btn btn-neutral float-left" title="uses/2" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a>
        <a href="../predicates/index.html" class="btn btn-neutral float-right" title="Built-in predicates" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a>
    </div>

  <hr/>

  <div role="contentinfo">
    <p>&#169; Copyright 1998-2025, Paulo Moura.</p>
  </div>

  Built with <a href="https://www.sphinx-doc.org/">Sphinx</a> using a
    <a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a>
    provided by <a href="https://readthedocs.org">Read the Docs</a>.
   

</footer>
        </div>
      </div>
    </section>
  </div>
  <script>
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script> 

</body>
</html>